﻿Public Class frmEtiketParametreleri

    Private EtiketListesi As List(Of MikroMagazaObject.EtiketSettingsObject)

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim dlg As New OpenFileDialog
        If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            txt_ean13.Text = dlg.FileName
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim dlg As New OpenFileDialog
        If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            txt_ean8.Text = dlg.FileName
        End If
    End Sub
    Private Sub Ekle()
        Dim bulundu As Boolean = False
        For i As Integer = 0 To EtiketListesi.Count - 1
            If TextBox1.Text = EtiketListesi(i).Adi Then
                EtiketListesi(i).Ean13 = txt_ean13.Text
                EtiketListesi(i).Ean8 = txt_ean8.Text
                EtiketListesi(i).Printer = cmb_etiket.Text
                bulundu = True
                Exit For
            End If
        Next
        If bulundu = False Then
            Dim etk As New MikroMagazaObject.EtiketSettingsObject
            etk.Printer = cmb_etiket.Text
            etk.Ean8 = txt_ean8.Text
            etk.Ean13 = txt_ean13.Text
            etk.Adi = TextBox1.Text
            EtiketListesi.Add(etk)
        End If
        MikroMagazaObject.Settings.SaveSettings()
        Me.Close()
    End Sub

    Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
        Ekle()
        DataGridView1.DataSource = EtiketListesi
    End Sub

    Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Try
            TextBox1.Text = DataGridView1(0, e.RowIndex).Value
            txt_ean13.Text = DataGridView1(1, e.RowIndex).Value
            txt_ean8.Text = DataGridView1(2, e.RowIndex).Value
            cmb_etiket.SelectedItem = DataGridView1(3, e.RowIndex).Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub frmEtiketParametreleri_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cmb_etiket.Items.AddRange(New String() {"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10", "LPT1", "LPT2", "LPT3", "LPT4"})
        For Each prn As String In System.Drawing.Printing.PrinterSettings.InstalledPrinters
            cmb_etiket.Items.Add(prn)
        Next
        EtiketListesi = MikroMagazaObject.Settings.Get.EtiketAyarlari
        DataGridView1.DataSource = EtiketListesi
    End Sub

    Private Sub SimpleButton2_Click(sender As Object, e As EventArgs) Handles SimpleButton2.Click
        If (DataGridView1.SelectedRows.Count > 0) Then
            EtiketListesi.RemoveAt(DataGridView1.SelectedRows(0).Index)
            Me.Close()
        End If
    End Sub
End Class